package com.tests;/*
 *Author:cxz
 *@Date:${Date}
 */

import com.User;
import com.dao.IUserMapper;
import com.dao.Users;
import com.io.Resource;
import java.io.InputStream;
import java.util.List;
import org.junit.Test;
import sqlSession.SqlSession;
import sqlSession.SqlSessionFactory;
import sqlSession.SqlSessionFactoryBuilder;
import sqlSessionGetMapper.io.GetMapperResource;
import sqlSessionGetMapper.sqlSession.GetMapperSqlSession;
import sqlSessionGetMapper.sqlSession.GetMapperSqlSessionFactory;
import sqlSessionGetMapper.sqlSession.SqlSessionBuider;

/*
@ClassName Tests

*@Description
*@Author cxz
*@Date 2020/4/6 9:38
*Version V1.0
*/
public class Tests {

  @Test
  public void test() throws Exception {
    InputStream resourceAsSteam = Resource.getResource("sqlMapper.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsSteam);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    User user = new User();
    user.setPassword("dd");
    user.setType("2");
    //User user2 = sqlSession("User.selectOne", user);
    List<User> objects = sqlSession.selectList("User.selectList", user);
    System.out.println(objects.get(0));

  }

  @Test
  public void test2() throws Exception {
    InputStream resourceAsSteam = GetMapperResource.getResource("sqlMapper.xml");
    //SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsSteam);
    //SqlSession sqlSession = sqlSessionFactory.openSession();
    GetMapperSqlSessionFactory sqlSessionFactory = new SqlSessionBuider().buider(resourceAsSteam);
    GetMapperSqlSession getMapperSqlSession = sqlSessionFactory.oppenSession();
    //调用
    Users user = new Users();
    user.setId(1);
    user.setName("ddd");
      /*  User user2 = sqlSession.selectOne("user.selectOne", user);

        System.out.println(user2);*/

       /* List<User> users = sqlSession.selectList("user.selectList");
        for (User user1 : users) {
            System.out.println(user1);
        }*/

    // IUserDao userDao = sqlSession.getMapper(IUserDao.class);
    IUserMapper iUserMapper = getMapperSqlSession.getMapper(IUserMapper.class);
    iUserMapper.insertUser(user);
    // iUserMapper.updateUser(user);
  /*  List<User> all = userDao.findAll();
    for (User user1 : all) {
      System.out.println(user1);
    }*/

  }
}
